<?php
/*Modelo Cliente*/
class Insumo_model extends Model
{
	function Insumo_model()
	{
		parent::Model();
	}
	
	function listaInsumos(){
		$sql = "
		SELECT
		insumo.cod_insumo,
		insumo.nom_insumo,
		insumo.und_medida
		FROM
		insumo";
		
		$query = $this->db->query($sql);
		return $query;
	}
	
	function infoInsumo($cod_insumo){
		$sql = "SELECT
		insumo.cod_insumo,
		insumo.nom_insumo,
		insumo.und_medida
		FROM
		insumo
		WHERE 
		insumo.cod_insumo = '".$cod_insumo."'";
		$query = $this->db->query($sql);
		return $query;
	}
	
	function guardarInsumo($data){
		$this->db->insert('insumo', $data);
		
	}
	
	function modificarInsumo($data, $where){
		$this->db->update('insumo', $data, $where);
	}
	
	function eliminarInsumo($cod_insumo){
		$sql_verify="
			SELECT
			`insumo`.`cod_insumo`
			FROM
			`insumo`
			WHERE
			`insumo`.`cod_insumo` =  '".$cod_insumo."' AND
			`insumo`.`activo_insumo` =  '1'";
		
		$query = $this->db->query($sql_verify);
		/*0 falso
		1 verdad*/
		//echo $query->num_rows();
		if($query->num_rows() == 0){
			$sql="DELETE FROM
			`insumo`
			WHERE
			`insumo`.`cod_insumo` =  '".$cod_insumo."'" ;
			$query = $this->db->query($sql);
			return 1;
		}else{
			return 0;
		}
	}
}
?>